package club.emergency.wechat.mistake_collection.operate.provider.impl;

import club.emergency.wechat.common.response.ResponseEntity;
import club.emergency.wechat.common.response.StatusCode;
import club.emergency.wechat.mistake_collection.operate.MistakeCollectionOperate;
import club.emergency.wechat.model.mistake_collection.MistakeCollection;
import club.emergency.wechat.persistence.mistake_collection.MistakeCollectionMapper;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Create with IntelliJ IDEA
 * Project Name: wechat
 * Package Name: club.emergency.wechat.mistake_collection.operate.provider.impl
 * Date: 2018/12/23
 *
 * @author: 快乐的小菌菌
 * Description:
 */
@RestController
@Transactional(rollbackFor = Exception.class)
public class MistakeCollectionOperateImpl implements MistakeCollectionOperate {

    private MistakeCollectionMapper mistakeCollectionMapper;

    public MistakeCollectionOperateImpl(MistakeCollectionMapper mistakeCollectionMapper) {
        this.mistakeCollectionMapper = mistakeCollectionMapper;
    }

    @Override
    public String save(@RequestBody MistakeCollection mistakeCollection) {
        mistakeCollectionMapper.insert(mistakeCollection);
        return ResponseEntity.ok(StatusCode.DB_SAVE_OK, "新增错题成功", mistakeCollection.getId());
    }

    @Override
    public String eliminate(@RequestParam("id") Long id) {
        mistakeCollectionMapper.deleteById(id);
        return ResponseEntity.ok(StatusCode.DB_REMOVE_OK, "消灭错题成功");
    }

}
